<?php
namespace app\index\controller;

use app\index\model\FlowLogModel;
use app\index\model\MainBaseCaiModel;
use app\index\model\MainBaseDianModel;
use app\index\model\MainBaseFenModel;
use app\index\model\MainBaseJiModel;
use app\index\model\MainBaseRenModel;
use app\index\model\MainJianChuiListModel;
use app\index\model\MainJianChuiModel;
use app\index\model\MainJianCuoListModel;
use app\index\model\MainJianCuoModel;
use app\index\model\MainJianGongListModel;
use app\index\model\MainJianGongModel;
use app\index\model\MainJianGuanListModel;
use app\index\model\MainJianGuanModel;
use app\index\model\MainMarkCaiListModel;
use app\index\model\MainMarkCaiModel;
use app\index\model\MainMarkFenListModel;
use app\index\model\MainMarkFenModel;
use app\index\model\MainMarkJiListModel;
use app\index\model\MainMarkJiModel;
use app\index\model\MainMarkRenListModel;
use app\index\model\MainMarkRenModel;
use app\index\model\MainOptionModel;
use app\index\model\UserModel;
use app\index\service\MainService;
use app\index\service\MenuService;
use app\index\service\OptService;
use app\index\service\UserService;
use think\Db;
use think\Request;

class Mainbase extends Common
{

    public function get_main_option(Request $request)
    {
        $numname = $request->param('numname', '', 'string');
        $data = (new MainService())->get_base_info($numname);
        return outputJson(2000,lang('code_2000'),$data);
    }


    public function list_main_option(Request $request){
        $opid = $request->post('opid', 0, 'int');

        if($opid){
            $data['data'] = (new MainService())->get_optioninfo_all($opid);
        }else{
            $data['data'] = [];
        }

        $data['butauth'] = (new MenuService())->get_butauth('main_option');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function list_main_option_nav(Request $request){
        $data = [];
        $nav = [
            'main' => '造价模块',
        ];
        foreach ($nav as $k=>$v){
            $item['title'] = $v;
            $item['spread'] = true;
            $item['children'] = MainOptionModel::field('id,name as title')->where(['pid'=>0,'modname'=>$k])->order('sort ASC')->select()->toArray();
            $data[] = $item;
        }
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_option(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }
            if((new MainService())->check_option_name($param['name'], $param['opid'])){
                return outputJson(4000, '名称已存在');
            }
            if(empty($param['keyid'])){
                return outputJson(4000, '请输入键值');
            }
            if((new MainService())->check_option_keyid($param['keyid'], $param['opid'])){
                return outputJson(4000, '键值已存在');
            }


            if(empty($param['pid'])){
                $param['pid'] = $param['opid'];
            }

            $param['topid'] = $param['opid'];
            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            unset($param['token']);
            unset($param['opid']);

            Db::startTrans();
            try {
                $optionid = MainOptionModel::insertGetId($param);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_option', $optionid, '基础数据');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $opid = $request->get('opid',0,'int');
            if($opid){
                $data['pidArr'] = (new MainService())->get_optioninfo_all($opid);
            }else{
                $data['pidArr'] = [];
            }

            $maxKeyid = MainOptionModel::where(['comid'=>$this->userinfo['comid'],'topid'=>$opid,'deleted_user'=>0])->max('keyid');
            $data['keyid'] = $maxKeyid+1;

            $maxsort = MainOptionModel::where(['comid'=>$this->userinfo['comid'],'topid'=>$opid,'deleted_user'=>0])->max('sort');
            $data['sort'] = $maxsort+1;
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function addson_main_option(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }

            $pidinfo = MainOptionModel::where(['id'=>$param['id']])->find();

            if((new MainService())->check_option_name($param['name'], $pidinfo['topid'])){
                return outputJson(4000, '名称已存在');
            }
            if(empty($param['keyid'])){
                return outputJson(4000, '请输入键值');
            }
            if((new MainService())->check_option_keyid($param['keyid'], $pidinfo['topid'])){
                return outputJson(4000, '键值已存在');
            }


            $param['pid'] = $pidinfo['id'];
            $param['topid'] = $pidinfo['topid'];

            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            unset($param['token']);
            unset($param['id']);

            Db::startTrans();
            try {
                $optionid = MainOptionModel::insertGetId($param);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_option', $optionid, '基础数据');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainOptionModel::where(['id'=>$id])->find();
            $maxKeyid = MainOptionModel::where(['comid'=>$this->userinfo['comid'],'topid'=>$data['data']['topid']])->max('keyid');
            $data['keyid'] = $maxKeyid+1;


            $maxsort = MainOptionModel::where(['comid'=>$this->userinfo['comid'],'topid'=>$data['data']['topid'],'deleted_user'=>0])
                ->where(['pid'=>$data['data']['id']])->max('sort');
            $data['sort'] = $maxsort+1;
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function edit_main_option(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }

            $pidinfo = MainOptionModel::where(['id'=>$param['id']])->find();

            if((new MainService())->check_option_name($param['name'], $pidinfo['topid'], $param['id'])){
                return outputJson(4000, '名称已存在');
            }
            if(empty($param['keyid'])){
                return outputJson(4000, '请输入键值');
            }
            if((new MainService())->check_option_keyid($param['keyid'], $pidinfo['topid'], $param['id'])){
                return outputJson(4000, '键值已存在');
            }

            if(empty($param['pid'])){
                $param['pid'] = $pidinfo['topid'];
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at']= date('Y-m-d H:i:s');
            unset($param['token']);

            Db::startTrans();
            try {
                MainOptionModel::update($param);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_option', $param['id'], '基础数据');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data = MainOptionModel::where(['id'=>$id])->find();
            if($data['topid']){
                $data['pidArr'] = (new MainService())->get_optioninfo_all($data['topid']);
            }else{
                $data['pidArr'] = [];
            }
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function move_main_option(Request $request){
        if($request->isPost()){
            $id = $request->post('id', 0, 'int');
            $type = $request->post('type', 0, 'int');

            $data = MainOptionModel::where(['id'=>$id])->find();
            if(!$data){
                return outputJson(2000,lang('code_2000'));
            }

            $list = MainOptionModel::where(['pid'=>$data['pid'],'topid'=>$data['topid'],'deleted_user'=>0])->order('sort ASC')->column('id');
            if(count($list) < 2){
                return outputJson(2000,lang('code_2000'));
            }

            $info = [];
            if($type == 1){
                foreach ($list as $k=>$opid){
                    if($opid == $data['id']){
                        if($k == 0){
                            $info[] = $opid;
                        }else{
                            $info[$k-1] = $opid;
                            $info[$k] = $list[$k-1];
                        }
                    }else{
                        $info[] = $opid;
                    }
                }
            }elseif($type == 2){
                foreach ($list as $k=>$opid){
                    if($k > 0){
                        if($list[$k-1] == $data['id']){
                            $info[$k-1] = $opid;
                            $info[$k] = $list[$k-1];
                        }else{
                            $info[] = $opid;
                        }
                    }else{
                        $info[] = $opid;
                    }
                }
            }else{
                $info = $list;
            }

            Db::startTrans();
            try {
                $sort = 1;
                foreach ($info as $_opid){
                    MainOptionModel::where(['id'=>$_opid])->update(['sort'=>$sort]);
                    $sort++;
                }

                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(2000,lang('code_2000'));
            }
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function del_main_option(Request $request){
        $param = $request->post();
        $data = MainOptionModel::where(['id'=>$param['id']])->find();
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        if( MainOptionModel::where(['pid'=>$data['id'],'deleted_user'=>0])->find() ){
            return outputJson(4000, '该数据下存在子级数据，不能删除');
        }

        if( $data['isdea'] > 0 ){
            return outputJson(4000, '系统预设数据，不能删除');
        }

        Db::startTrans();
        try {
            MainOptionModel::where(['id'=>$data['id']])->update([
                'deleted_user'=> $this->userinfo['id'],
                'deleted_at'=> date('Y-m-d H:i:s'),
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_option', $data['id'], '基础数据');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }





    public function list_main_base_cai(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['cai.deleted_user','=', 0];
        $where[] = ['cai.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['cai.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['basetype']) && !empty($param['basetype'])){
            $where[] = ['cai.basetype_cai','=', $param['basetype']];
        }
        if(isset($param['basetype_cai']) && !empty($param['basetype_cai'])){
            $where[] = ['cai.basetype_cai','=', $param['basetype_cai']];
        }
        if(isset($param['areas']) && !empty($param['areas'])){
            $where[] = ['cai.areas','like', '%'.$param['areas'].'%'];
        }
        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['cai.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['xiangtype']) && !empty($param['xiangtype'])){
            $where[] = ['cai.xiangtype','=', $param['xiangtype']];
        }
        if(isset($param['shidt']) && !empty($param['shidt'])){
            $where[] = ['cai.shidt','like', '%'.$param['shidt'].'%'];
        }
        if(isset($param['gongtype_cai']) && !empty($param['gongtype_cai'])){
            $where[] = ['cai.gongtype_cai','=', $param['gongtype_cai']];
        }
        if(isset($param['painame']) && !empty($param['painame'])){
            $where[] = ['cai.painame','like', '%'.$param['painame'].'%'];
        }
        if(isset($param['pinname']) && !empty($param['pinname'])){
            $where[] = ['cai.pinname','like', '%'.$param['pinname'].'%'];
        }
        if(isset($param['guige']) && !empty($param['guige'])){
            $where[] = ['cai.guige','like', '%'.$param['guige'].'%'];
        }
        if(isset($param['valunit']) && !empty($param['valunit'])){
            $where[] = ['cai.valunit','like', '%'.$param['valunit'].'%'];
        }
        if(isset($param['noratefee']) && !empty($param['noratefee'])){
            $where[] = ['cai.noratefee','like', '%'.$param['noratefee'].'%'];
        }
        if(isset($param['gongname']) && !empty($param['gongname'])){
            $where[] = ['cai.gongname','like', '%'.$param['gongname'].'%'];
        }
        if(isset($param['gongtel']) && !empty($param['gongtel'])){
            $where[] = ['cai.gongtel','like', '%'.$param['gongtel'].'%'];
        }
        if(isset($param['pridt']) && !empty($param['pridt'])){
            $where[] = ['cai.pridt','between', explode(' - ', $param['pridt'])];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['cai.explain','like', '%'.$param['explain'].'%'];
        }
        if(isset($param['explaintwo']) && !empty($param['explaintwo'])){
            $where[] = ['cai.explaintwo','like', '%'.$param['explaintwo'].'%'];
        }



        $data['basetype_cai'] = (new MainService())->get_base_info('basetype_cai');
        $data['is_basetype_cai'] = isset($param['basetype_cai']) ? $param['basetype_cai'] : '';

        $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
        $data['is_xiangtype'] = isset($param['xiangtype']) ? $param['xiangtype'] : '';

        $data['gongtype_cai'] = (new MainService())->get_base_info('gongtype_cai');
        $data['is_gongtype_cai'] = isset($param['gongtype_cai']) ? $param['gongtype_cai'] : '';


        $data['data'] = MainBaseCaiModel::alias('cai')
            ->field('cai.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_base_cai', 'cai'))
            ->order('cai.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['basetype_cai'] = (new MainService())->get_base_showname('basetype_cai', $item['basetype_cai']);
                $item['xiangtype'] = (new MainService())->get_base_showname('xiangtype', $item['xiangtype']);
                $item['gongtype_cai'] = (new MainService())->get_base_showname('gongtype_cai', $item['gongtype_cai']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_base_cai');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_base_cai(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['basetype_cai'])){
                return outputJson(4000, '请选择分类');
            }
            if(empty($param['pinname'])){
                return outputJson(4000, '请输入材料名称');
            }
            if(empty($param['noratefee'])){
                return outputJson(4000, '请输入不含税单价');
            }


            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainBaseCaiModel::insertGetId($param);
                (new OptService())->relation_file($files,'main_base_cai',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_base_cai', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_base_cai', $id, '材料价格库');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),['id'=>$id]);
        }else{
            $data['basetype_cai'] = (new MainService())->get_base_info('basetype_cai');
            $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
            $data['gongtype_cai'] = (new MainService())->get_base_info('gongtype_cai');
            $data['areas'] = (new OptService())->get_city_cader();
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_main_base_cai(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['basetype_cai'])){
                return outputJson(4000, '请选择分类');
            }
            if(empty($param['pinname'])){
                return outputJson(4000, '请输入材料名称');
            }
            if(empty($param['noratefee'])){
                return outputJson(4000, '请输入不含税单价');
            }

            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);

            Db::startTrans();
            try {
                MainBaseCaiModel::update($param);
                (new OptService())->relation_file($files,'main_base_cai',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_base_cai', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_base_cai', $param['id'], '材料价格库');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainBaseCaiModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            $data['basetype_cai'] = (new MainService())->get_base_info('basetype_cai');
            $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
            $data['gongtype_cai'] = (new MainService())->get_base_info('gongtype_cai');
            $data['areas'] = (new OptService())->get_city_cader();
            $data['files'] = (new OptService())->get_file('main_base_cai', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_base_cai(Request $request){
        $param = $request->post();
        $data = MainBaseCaiModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainBaseCaiModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_base_cai', $data['id'], '材料价格库');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_main_base_cai(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = MainBaseCaiModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }
        $data['data']['basetype_cai'] = (new MainService())->get_base_showname('basetype_cai', $data['data']['basetype_cai']);
        $data['data']['xiangtype'] = (new MainService())->get_base_showname('xiangtype', $data['data']['xiangtype']);
        $data['data']['gongtype_cai'] = (new MainService())->get_base_showname('gongtype_cai', $data['data']['gongtype_cai']);
        $data['files'] = (new OptService())->get_file('main_base_cai', $data['data']['id']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_main_base_ren(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['ren.deleted_user','=', 0];
        $where[] = ['ren.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['ren.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['basetype']) && !empty($param['basetype'])){
            $where[] = ['cai.basetype_ren','=', $param['basetype']];
        }
        if(isset($param['basetype_ren']) && !empty($param['basetype_ren'])){
            $where[] = ['ren.basetype_ren','=', $param['basetype_ren']];
        }
        if(isset($param['areas']) && !empty($param['areas'])){
            $where[] = ['ren.areas','like', '%'.$param['areas'].'%'];
        }
        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['ren.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['xiangtype']) && !empty($param['xiangtype'])){
            $where[] = ['ren.xiangtype','=', $param['xiangtype']];
        }
        if(isset($param['shidt']) && !empty($param['shidt'])){
            $where[] = ['ren.shidt','like', '%'.$param['shidt'].'%'];
        }
        if(isset($param['gongtype_ren']) && !empty($param['gongtype_ren'])){
            $where[] = ['ren.gongtype_ren','=', $param['gongtype_ren']];
        }
        if(isset($param['pinname']) && !empty($param['pinname'])){
            $where[] = ['ren.pinname','like', '%'.$param['pinname'].'%'];
        }
        if(isset($param['guige']) && !empty($param['guige'])){
            $where[] = ['ren.guige','like', '%'.$param['guige'].'%'];
        }
        if(isset($param['valunit']) && !empty($param['valunit'])){
            $where[] = ['ren.valunit','like', '%'.$param['valunit'].'%'];
        }
        if(isset($param['noratefee']) && !empty($param['noratefee'])){
            $where[] = ['ren.noratefee','like', '%'.$param['noratefee'].'%'];
        }
        if(isset($param['gongtel']) && !empty($param['gongtel'])){
            $where[] = ['ren.gongtel','like', '%'.$param['gongtel'].'%'];
        }
        if(isset($param['pridt']) && !empty($param['pridt'])){
            $where[] = ['ren.pridt','between', explode(' - ', $param['pridt'])];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['ren.explain','like', '%'.$param['explain'].'%'];
        }
        if(isset($param['explaintwo']) && !empty($param['explaintwo'])){
            $where[] = ['ren.explaintwo','like', '%'.$param['explaintwo'].'%'];
        }



        $data['basetype_ren'] = (new MainService())->get_base_info('basetype_ren');
        $data['is_basetype_ren'] = isset($param['basetype_ren']) ? $param['basetype_ren'] : '';

        $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
        $data['is_xiangtype'] = isset($param['xiangtype']) ? $param['xiangtype'] : '';

        $data['gongtype_ren'] = (new MainService())->get_base_info('gongtype_ren');
        $data['is_gongtype_ren'] = isset($param['gongtype_ren']) ? $param['gongtype_ren'] : '';


        $data['data'] = MainBaseRenModel::alias('ren')
            ->field('ren.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_base_ren', 'ren'))
            ->order('ren.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['basetype_ren'] = (new MainService())->get_base_showname('basetype_ren', $item['basetype_ren']);
                $item['xiangtype'] = (new MainService())->get_base_showname('xiangtype', $item['xiangtype']);
                $item['gongtype_ren'] = (new MainService())->get_base_showname('gongtype_ren', $item['gongtype_ren']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_base_ren');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_base_ren(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['basetype_ren'])){
                return outputJson(4000, '请选择分类');
            }
            if(empty($param['pinname'])){
                return outputJson(4000, '请输入清单名称');
            }
            if(empty($param['noratefee'])){
                return outputJson(4000, '请输入不含税单价');
            }


            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainBaseRenModel::insertGetId($param);
                (new OptService())->relation_file($files,'main_base_ren',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_base_ren', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_base_ren', $id, '人工价格库');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),['id'=>$id]);
        }else{
            $data['basetype_ren'] = (new MainService())->get_base_info('basetype_ren');
            $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
            $data['gongtype_ren'] = (new MainService())->get_base_info('gongtype_ren');
            $data['areas'] = (new OptService())->get_city_cader();
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_main_base_ren(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['basetype_ren'])){
                return outputJson(4000, '请选择分类');
            }
            if(empty($param['pinname'])){
                return outputJson(4000, '请输入清单名称');
            }
            if(empty($param['noratefee'])){
                return outputJson(4000, '请输入不含税单价');
            }

            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);

            Db::startTrans();
            try {
                MainBaseRenModel::update($param);
                (new OptService())->relation_file($files,'main_base_ren',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_base_ren', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_base_ren', $param['id'], '人工价格库');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainBaseRenModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            $data['basetype_ren'] = (new MainService())->get_base_info('basetype_ren');
            $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
            $data['gongtype_ren'] = (new MainService())->get_base_info('gongtype_ren');
            $data['areas'] = (new OptService())->get_city_cader();
            $data['files'] = (new OptService())->get_file('main_base_ren', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_base_ren(Request $request){
        $param = $request->post();
        $data = MainBaseRenModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainBaseRenModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_base_ren', $data['id'], '人工价格库');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_main_base_ren(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = MainBaseRenModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }
        $data['data']['basetype_ren'] = (new MainService())->get_base_showname('basetype_ren', $data['data']['basetype_ren']);
        $data['data']['xiangtype'] = (new MainService())->get_base_showname('xiangtype', $data['data']['xiangtype']);
        $data['data']['gongtype_ren'] = (new MainService())->get_base_showname('gongtype_ren', $data['data']['gongtype_ren']);
        $data['files'] = (new OptService())->get_file('main_base_ren', $data['data']['id']);
        return outputJson(2000,lang('code_2000'), $data);
    }


    public function list_main_base_ji(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['ji.deleted_user','=', 0];
        $where[] = ['ji.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['ji.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['basetype']) && !empty($param['basetype'])){
            $where[] = ['cai.basetype_ji','=', $param['basetype']];
        }
        if(isset($param['basetype_ji']) && !empty($param['basetype_ji'])){
            $where[] = ['ji.basetype_ji','=', $param['basetype_ji']];
        }
        if(isset($param['areas']) && !empty($param['areas'])){
            $where[] = ['ji.areas','like', '%'.$param['areas'].'%'];
        }
        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['ji.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['xiangtype']) && !empty($param['xiangtype'])){
            $where[] = ['ji.xiangtype','=', $param['xiangtype']];
        }
        if(isset($param['shidt']) && !empty($param['shidt'])){
            $where[] = ['ji.shidt','like', '%'.$param['shidt'].'%'];
        }
        if(isset($param['gongtype_ji']) && !empty($param['gongtype_ji'])){
            $where[] = ['ji.gongtype_ji','=', $param['gongtype_ji']];
        }
        if(isset($param['pinname']) && !empty($param['pinname'])){
            $where[] = ['ji.pinname','like', '%'.$param['pinname'].'%'];
        }
        if(isset($param['guige']) && !empty($param['guige'])){
            $where[] = ['ji.guige','like', '%'.$param['guige'].'%'];
        }
        if(isset($param['valunit']) && !empty($param['valunit'])){
            $where[] = ['ji.valunit','like', '%'.$param['valunit'].'%'];
        }
        if(isset($param['noratefee']) && !empty($param['noratefee'])){
            $where[] = ['ji.noratefee','like', '%'.$param['noratefee'].'%'];
        }
        if(isset($param['gongtel']) && !empty($param['gongtel'])){
            $where[] = ['ji.gongtel','like', '%'.$param['gongtel'].'%'];
        }
        if(isset($param['pridt']) && !empty($param['pridt'])){
            $where[] = ['ji.pridt','between', explode(' - ', $param['pridt'])];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['ji.explain','like', '%'.$param['explain'].'%'];
        }
        if(isset($param['explaintwo']) && !empty($param['explaintwo'])){
            $where[] = ['ji.explaintwo','like', '%'.$param['explaintwo'].'%'];
        }



        $data['basetype_ji'] = (new MainService())->get_base_info('basetype_ji');
        $data['is_basetype_ji'] = isset($param['basetype_ji']) ? $param['basetype_ji'] : '';

        $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
        $data['is_xiangtype'] = isset($param['xiangtype']) ? $param['xiangtype'] : '';

        $data['gongtype_ji'] = (new MainService())->get_base_info('gongtype_ji');
        $data['is_gongtype_ji'] = isset($param['gongtype_ji']) ? $param['gongtype_ji'] : '';


        $data['data'] = MainBaseJiModel::alias('ji')
            ->field('ji.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_base_ji', 'ji'))
            ->order('ji.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['basetype_ji'] = (new MainService())->get_base_showname('basetype_ji', $item['basetype_ji']);
                $item['xiangtype'] = (new MainService())->get_base_showname('xiangtype', $item['xiangtype']);
                $item['gongtype_ji'] = (new MainService())->get_base_showname('gongtype_ji', $item['gongtype_ji']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_base_ji');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_base_ji(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['basetype_ji'])){
                return outputJson(4000, '请选择分类');
            }
            if(empty($param['pinname'])){
                return outputJson(4000, '请输入机械名称');
            }
            if(empty($param['noratefee'])){
                return outputJson(4000, '请输入不含税单价');
            }


            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainBaseJiModel::insertGetId($param);
                (new OptService())->relation_file($files,'main_base_ji',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_base_ji', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_base_ji', $id, '机械价格库');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),['id'=>$id]);
        }else{
            $data['basetype_ji'] = (new MainService())->get_base_info('basetype_ji');
            $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
            $data['gongtype_ji'] = (new MainService())->get_base_info('gongtype_ji');
            $data['areas'] = (new OptService())->get_city_cader();
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_main_base_ji(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['basetype_ji'])){
                return outputJson(4000, '请选择分类');
            }
            if(empty($param['pinname'])){
                return outputJson(4000, '请输入机械名称');
            }
            if(empty($param['noratefee'])){
                return outputJson(4000, '请输入不含税单价');
            }

            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);

            Db::startTrans();
            try {
                MainBaseJiModel::update($param);
                (new OptService())->relation_file($files,'main_base_ji',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_base_ji', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_base_ji', $param['id'], '机械价格库');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainBaseJiModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            $data['basetype_ji'] = (new MainService())->get_base_info('basetype_ji');
            $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
            $data['gongtype_ji'] = (new MainService())->get_base_info('gongtype_ji');
            $data['areas'] = (new OptService())->get_city_cader();
            $data['files'] = (new OptService())->get_file('main_base_ji', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_base_ji(Request $request){
        $param = $request->post();
        $data = MainBaseJiModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainBaseJiModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_base_ji', $data['id'], '机械价格库');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_main_base_ji(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = MainBaseJiModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }
        $data['data']['basetype_ji'] = (new MainService())->get_base_showname('basetype_ji', $data['data']['basetype_ji']);
        $data['data']['xiangtype'] = (new MainService())->get_base_showname('xiangtype', $data['data']['xiangtype']);
        $data['data']['gongtype_ji'] = (new MainService())->get_base_showname('gongtype_ji', $data['data']['gongtype_ji']);
        $data['files'] = (new OptService())->get_file('main_base_ji', $data['data']['id']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_main_base_fen(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['fen.deleted_user','=', 0];
        $where[] = ['fen.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['fen.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['basetype']) && !empty($param['basetype'])){
            $where[] = ['cai.basetype_fen','=', $param['basetype']];
        }
        if(isset($param['basetype_fen']) && !empty($param['basetype_fen'])){
            $where[] = ['fen.basetype_fen','=', $param['basetype_fen']];
        }
        if(isset($param['areas']) && !empty($param['areas'])){
            $where[] = ['fen.areas','like', '%'.$param['areas'].'%'];
        }
        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['fen.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['xiangtype']) && !empty($param['xiangtype'])){
            $where[] = ['fen.xiangtype','=', $param['xiangtype']];
        }
        if(isset($param['shidt']) && !empty($param['shidt'])){
            $where[] = ['fen.shidt','like', '%'.$param['shidt'].'%'];
        }
        if(isset($param['gongtype_fen']) && !empty($param['gongtype_fen'])){
            $where[] = ['fen.gongtype_fen','=', $param['gongtype_fen']];
        }
        if(isset($param['pinname']) && !empty($param['pinname'])){
            $where[] = ['fen.pinname','like', '%'.$param['pinname'].'%'];
        }
        if(isset($param['guige']) && !empty($param['guige'])){
            $where[] = ['fen.guige','like', '%'.$param['guige'].'%'];
        }
        if(isset($param['valunit']) && !empty($param['valunit'])){
            $where[] = ['fen.valunit','like', '%'.$param['valunit'].'%'];
        }
        if(isset($param['noratefee']) && !empty($param['noratefee'])){
            $where[] = ['fen.noratefee','like', '%'.$param['noratefee'].'%'];
        }
        if(isset($param['gongtel']) && !empty($param['gongtel'])){
            $where[] = ['fen.gongtel','like', '%'.$param['gongtel'].'%'];
        }
        if(isset($param['pridt']) && !empty($param['pridt'])){
            $where[] = ['fen.pridt','between', explode(' - ', $param['pridt'])];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['fen.explain','like', '%'.$param['explain'].'%'];
        }
        if(isset($param['explaintwo']) && !empty($param['explaintwo'])){
            $where[] = ['fen.explaintwo','like', '%'.$param['explaintwo'].'%'];
        }



        $data['basetype_fen'] = (new MainService())->get_base_info('basetype_fen');
        $data['is_basetype_fen'] = isset($param['basetype_fen']) ? $param['basetype_fen'] : '';

        $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
        $data['is_xiangtype'] = isset($param['xiangtype']) ? $param['xiangtype'] : '';

        $data['gongtype_fen'] = (new MainService())->get_base_info('gongtype_fen');
        $data['is_gongtype_fen'] = isset($param['gongtype_fen']) ? $param['gongtype_fen'] : '';


        $data['data'] = MainBaseFenModel::alias('fen')
            ->field('fen.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_base_fen', 'fen'))
            ->order('fen.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['basetype_fen'] = (new MainService())->get_base_showname('basetype_fen', $item['basetype_fen']);
                $item['xiangtype'] = (new MainService())->get_base_showname('xiangtype', $item['xiangtype']);
                $item['gongtype_fen'] = (new MainService())->get_base_showname('gongtype_fen', $item['gongtype_fen']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_base_fen');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_base_fen(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['basetype_fen'])){
                return outputJson(4000, '请选择分类');
            }
            if(empty($param['pinname'])){
                return outputJson(4000, '请输入清单名称');
            }
            if(empty($param['noratefee'])){
                return outputJson(4000, '请输入不含税单价');
            }


            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainBaseFenModel::insertGetId($param);
                (new OptService())->relation_file($files,'main_base_fen',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_base_fen', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_base_fen', $id, '分包价格库');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),['id'=>$id]);
        }else{
            $data['basetype_fen'] = (new MainService())->get_base_info('basetype_fen');
            $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
            $data['gongtype_fen'] = (new MainService())->get_base_info('gongtype_fen');
            $data['areas'] = (new OptService())->get_city_cader();
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_main_base_fen(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['basetype_fen'])){
                return outputJson(4000, '请选择分类');
            }
            if(empty($param['pinname'])){
                return outputJson(4000, '请输入清单名称');
            }
            if(empty($param['noratefee'])){
                return outputJson(4000, '请输入不含税单价');
            }

            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);

            Db::startTrans();
            try {
                MainBaseFenModel::update($param);
                (new OptService())->relation_file($files,'main_base_fen',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_base_fen', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_base_fen', $param['id'], '分包价格库');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainBaseFenModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            $data['basetype_fen'] = (new MainService())->get_base_info('basetype_fen');
            $data['xiangtype'] = (new MainService())->get_base_info('xiangtype');
            $data['gongtype_fen'] = (new MainService())->get_base_info('gongtype_fen');
            $data['areas'] = (new OptService())->get_city_cader();
            $data['files'] = (new OptService())->get_file('main_base_fen', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_base_fen(Request $request){
        $param = $request->post();
        $data = MainBaseFenModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainBaseFenModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_base_fen', $data['id'], '分包价格库');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_main_base_fen(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = MainBaseFenModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }
        $data['data']['basetype_fen'] = (new MainService())->get_base_showname('basetype_fen', $data['data']['basetype_fen']);
        $data['data']['xiangtype'] = (new MainService())->get_base_showname('xiangtype', $data['data']['xiangtype']);
        $data['data']['gongtype_fen'] = (new MainService())->get_base_showname('gongtype_fen', $data['data']['gongtype_fen']);
        $data['files'] = (new OptService())->get_file('main_base_fen', $data['data']['id']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_main_base_dian(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['dian.deleted_user','=', 0];
        $where[] = ['dian.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['dian.name','like', '%'.$param['keyword'].'%'];
        }

        if(isset($param['basetype_dian']) && !empty($param['basetype_dian'])){
            $where[] = ['dian.basetype_dian','=', $param['basetype_dian']];
        }
        if(isset($param['pinname']) && !empty($param['pinname'])){
            $where[] = ['dian.pinname','like', '%'.$param['pinname'].'%'];
        }
        if(isset($param['valunit']) && !empty($param['valunit'])){
            $where[] = ['dian.valunit','like', '%'.$param['valunit'].'%'];
        }
        if(isset($param['noratefee']) && !empty($param['noratefee'])){
            $where[] = ['dian.noratefee','like', '%'.$param['noratefee'].'%'];
        }
        if(isset($param['pinpai']) && !empty($param['pinpai'])){
            $where[] = ['dian.pinpai','like', '%'.$param['pinpai'].'%'];
        }
        if(isset($param['gongname']) && !empty($param['gongname'])){
            $where[] = ['dian.gongname','like', '%'.$param['gongname'].'%'];
        }
        if(isset($param['gongtel']) && !empty($param['gongtel'])){
            $where[] = ['dian.gongtel','like', '%'.$param['gongtel'].'%'];
        }
        if(isset($param['pridt']) && !empty($param['pridt'])){
            $where[] = ['dian.pridt','between', explode(' - ', $param['pridt'])];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['dian.explain','like', '%'.$param['explain'].'%'];
        }
        if(isset($param['explaintwo']) && !empty($param['explaintwo'])){
            $where[] = ['dian.explaintwo','like', '%'.$param['explaintwo'].'%'];
        }



        $data['basetype_dian'] = (new MainService())->get_base_info('basetype_dian');
        $data['is_basetype_dian'] = isset($param['basetype_dian']) ? $param['basetype_dian'] : '';


        $data['data'] = MainBaseDianModel::alias('dian')
            ->field('dian.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_base_dian', 'dian'))
            ->order('dian.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['basetype_dian'] = (new MainService())->get_base_showname('basetype_dian', $item['basetype_dian']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_base_dian');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_base_dian(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['basetype_dian'])){
                return outputJson(4000, '请选择专业类别');
            }
            if(empty($param['pinname'])){
                return outputJson(4000, '请输入项目名称');
            }
            if(empty($param['noratefee'])){
                return outputJson(4000, '请输入不含税单价');
            }


            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainBaseDianModel::insertGetId($param);
                (new OptService())->relation_file($files,'main_base_dian',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_base_dian', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_base_dian', $id, '机电价格库');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $data['basetype_dian'] = (new MainService())->get_base_info('basetype_dian');
            $data['areas'] = (new OptService())->get_city_cader();
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_main_base_dian(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['basetype_dian'])){
                return outputJson(4000, '请选择专业类别');
            }
            if(empty($param['pinname'])){
                return outputJson(4000, '请输入项目名称');
            }
            if(empty($param['noratefee'])){
                return outputJson(4000, '请输入不含税单价');
            }

            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);

            Db::startTrans();
            try {
                MainBaseDianModel::update($param);
                (new OptService())->relation_file($files,'main_base_dian',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_base_dian', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_base_dian', $param['id'], '机电价格库');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainBaseDianModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            $data['basetype_dian'] = (new MainService())->get_base_info('basetype_dian');
            $data['areas'] = (new OptService())->get_city_cader();
            $data['files'] = (new OptService())->get_file('main_base_dian', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_base_dian(Request $request){
        $param = $request->post();
        $data = MainBaseDianModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainBaseDianModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_base_dian', $data['id'], '机电价格库');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_main_base_dian(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = MainBaseDianModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }
        $data['data']['basetype_dian'] = (new MainService())->get_base_showname('basetype_dian', $data['data']['basetype_dian']);
        $data['files'] = (new OptService())->get_file('main_base_dian', $data['data']['id']);
        return outputJson(2000,lang('code_2000'), $data);
    }





    public function list_main_mark_ren(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['ren.deleted_user','=', 0];
        $where[] = ['ren.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['ren.name|ren.explain','like', '%'.$param['keyword'].'%'];
        }


        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['ren.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['ren.explain','like', '%'.$param['explain'].'%'];
        }


        $data['data'] = MainMarkRenModel::alias('ren')
            ->field('ren.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_mark_ren', 'ren'))
            ->order('ren.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_mark_ren');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_mark_ren(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainMarkRenModel::insertGetId($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_mark_ren', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_mark_ren', $id, '基准费用人工费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'));
        }
    }
    public function edit_main_mark_ren(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            unset($param['token']);

            Db::startTrans();
            try {
                MainMarkRenModel::update($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_mark_ren', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_mark_ren', $param['id'], '基准费用人工费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainMarkRenModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function qing_main_mark_ren(Request $request){
        if($request->isPost()){
            $param = $request->post();

            $list = array_filter($param['list']);
            unset($param['list']);

            $paramZhu['updated_user'] = $this->userinfo['id'];
            $paramZhu['updated_at'] = date('Y-m-d H:i:s');

            Db::startTrans();
            try {
                MainMarkRenModel::where(['id'=>$param['id']])->update($paramZhu);

                MainMarkRenListModel::where(['markid'=>$param['id']])->delete();
                foreach($list as $vvv){
                    $vvv['markid'] = $param['id'];
                    MainMarkRenListModel::insert($vvv);
                }


                (new OptService())->add_flow_log('编辑清单', 'main_mark_ren', $param['id']);
                (new OptService())->add_log_list('编辑清单', 'main_mark_ren', $param['id'], '基准费用人工费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            $data['editshi'] = (new MainService())->get_editshi();
            return outputJson(2000,lang('code_2000'), $data);
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainMarkRenModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $data['basetype'] = (new MainService())->get_base_info('basetype_ren');
            $list = MainMarkRenListModel::where(['markid'=>$data['data']['id']])->select()->toArray();
            foreach ($list as &$item){
                $item['sourceInfo'] = MainBaseRenModel::where(['id'=>$item['source'],'deleted_user'=>0])->find();
            }
            $data['list'] = $list;
            $data['editshi'] = (new MainService())->get_editshi($data['data']['updated_at'],$data['data']['updated_user']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_mark_ren(Request $request){
        $param = $request->post();
        $data = MainMarkRenModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainMarkRenModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_mark_ren', $data['id'], '基准费用人工费');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }

    public function list_main_mark_cai(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['cai.deleted_user','=', 0];
        $where[] = ['cai.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['cai.name|cai.explain','like', '%'.$param['keyword'].'%'];
        }


        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['cai.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['cai.explain','like', '%'.$param['explain'].'%'];
        }


        $data['data'] = MainMarkCaiModel::alias('cai')
            ->field('cai.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_mark_cai', 'cai'))
            ->order('cai.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_mark_cai');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_mark_cai(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainMarkCaiModel::insertGetId($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_mark_cai', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_mark_cai', $id, '基准费用材料费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'));
        }
    }
    public function edit_main_mark_cai(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            unset($param['token']);

            Db::startTrans();
            try {
                MainMarkCaiModel::update($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_mark_cai', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_mark_cai', $param['id'], '基准费用材料费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainMarkCaiModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function qing_main_mark_cai(Request $request){
        if($request->isPost()){
            $param = $request->post();

            $list = array_filter($param['list']);
            unset($param['list']);

            $paramZhu['updated_user'] = $this->userinfo['id'];
            $paramZhu['updated_at'] = date('Y-m-d H:i:s');

            Db::startTrans();
            try {
                MainMarkCaiModel::where(['id'=>$param['id']])->update($paramZhu);

                MainMarkCaiListModel::where(['markid'=>$param['id']])->delete();
                foreach($list as $vvv){
                    $vvv['markid'] = $param['id'];
                    MainMarkCaiListModel::insert($vvv);
                }


                (new OptService())->add_flow_log('编辑清单', 'main_mark_cai', $param['id']);
                (new OptService())->add_log_list('编辑清单', 'main_mark_cai', $param['id'], '基准费用材料费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            $data['editshi'] = (new MainService())->get_editshi();
            return outputJson(2000,lang('code_2000'), $data);
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainMarkCaiModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $data['basetype'] = (new MainService())->get_base_info('basetype_cai');
            $list = MainMarkCaiListModel::where(['markid'=>$data['data']['id']])->select()->toArray();
            foreach ($list as &$item){
                $item['sourceInfo'] = MainBaseCaiModel::where(['id'=>$item['source'],'deleted_user'=>0])->find();
            }
            $data['list'] = $list;
            $data['editshi'] = (new MainService())->get_editshi($data['data']['updated_at'],$data['data']['updated_user']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_mark_cai(Request $request){
        $param = $request->post();
        $data = MainMarkCaiModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainMarkCaiModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_mark_cai', $data['id'], '基准费用材料费');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }

    public function list_main_mark_ji(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['ji.deleted_user','=', 0];
        $where[] = ['ji.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['ji.name|ji.explain','like', '%'.$param['keyword'].'%'];
        }


        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['ji.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['ji.explain','like', '%'.$param['explain'].'%'];
        }


        $data['data'] = MainMarkJiModel::alias('ji')
            ->field('ji.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_mark_ji', 'ji'))
            ->order('ji.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_mark_ji');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_mark_ji(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainMarkJiModel::insertGetId($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_mark_ji', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_mark_ji', $id, '基准费用机械费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'));
        }
    }
    public function edit_main_mark_ji(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            unset($param['token']);

            Db::startTrans();
            try {
                MainMarkJiModel::update($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_mark_ji', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_mark_ji', $param['id'], '基准费用机械费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainMarkJiModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function qing_main_mark_ji(Request $request){
        if($request->isPost()){
            $param = $request->post();

            $list = array_filter($param['list']);
            unset($param['list']);

            $paramZhu['updated_user'] = $this->userinfo['id'];
            $paramZhu['updated_at'] = date('Y-m-d H:i:s');

            Db::startTrans();
            try {
                MainMarkJiModel::where(['id'=>$param['id']])->update($paramZhu);

                MainMarkJiListModel::where(['markid'=>$param['id']])->delete();
                foreach($list as $vvv){
                    $vvv['markid'] = $param['id'];
                    MainMarkJiListModel::insert($vvv);
                }


                (new OptService())->add_flow_log('编辑清单', 'main_mark_ji', $param['id']);
                (new OptService())->add_log_list('编辑清单', 'main_mark_ji', $param['id'], '基准费用机械费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            $data['editshi'] = (new MainService())->get_editshi();
            return outputJson(2000,lang('code_2000'), $data);
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainMarkJiModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $data['basetype'] = (new MainService())->get_base_info('basetype_ji');
            $list = MainMarkJiListModel::where(['markid'=>$data['data']['id']])->select()->toArray();
            foreach ($list as &$item){
                $item['sourceInfo'] = MainBaseJiModel::where(['id'=>$item['source'],'deleted_user'=>0])->find();
            }
            $data['list'] = $list;
            $data['editshi'] = (new MainService())->get_editshi($data['data']['updated_at'],$data['data']['updated_user']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_mark_ji(Request $request){
        $param = $request->post();
        $data = MainMarkJiModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainMarkJiModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_mark_ji', $data['id'], '基准费用机械费');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }

    public function list_main_mark_fen(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['fen.deleted_user','=', 0];
        $where[] = ['fen.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['fen.name|fen.explain','like', '%'.$param['keyword'].'%'];
        }


        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['fen.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['fen.explain','like', '%'.$param['explain'].'%'];
        }


        $data['data'] = MainMarkFenModel::alias('fen')
            ->field('fen.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_mark_fen', 'fen'))
            ->order('fen.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_mark_fen');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_mark_fen(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainMarkFenModel::insertGetId($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_mark_fen', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_mark_fen', $id, '基准费用分包费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'));
        }
    }
    public function edit_main_mark_fen(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            unset($param['token']);

            Db::startTrans();
            try {
                MainMarkFenModel::update($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_mark_fen', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_mark_fen', $param['id'], '基准费用分包费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainMarkFenModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function qing_main_mark_fen(Request $request){
        if($request->isPost()){
            $param = $request->post();

            $list = array_filter($param['list']);
            unset($param['list']);

            $paramZhu['updated_user'] = $this->userinfo['id'];
            $paramZhu['updated_at'] = date('Y-m-d H:i:s');

            Db::startTrans();
            try {
                MainMarkFenModel::where(['id'=>$param['id']])->update($paramZhu);

                MainMarkFenListModel::where(['markid'=>$param['id']])->delete();
                foreach($list as $vvv){
                    $vvv['markid'] = $param['id'];
                    MainMarkFenListModel::insert($vvv);
                }


                (new OptService())->add_flow_log('编辑清单', 'main_mark_fen', $param['id']);
                (new OptService())->add_log_list('编辑清单', 'main_mark_fen', $param['id'], '基准费用分包费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            $data['editshi'] = (new MainService())->get_editshi();
            return outputJson(2000,lang('code_2000'), $data);
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainMarkFenModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $data['basetype'] = (new MainService())->get_base_info('basetype_fen');
            $list = MainMarkFenListModel::where(['markid'=>$data['data']['id']])->select()->toArray();
            foreach ($list as &$item){
                $item['sourceInfo'] = MainBaseFenModel::where(['id'=>$item['source'],'deleted_user'=>0])->find();
            }
            $data['list'] = $list;

            $data['editshi'] = (new MainService())->get_editshi($data['data']['updated_at'],$data['data']['updated_user']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_mark_fen(Request $request){
        $param = $request->post();
        $data = MainMarkFenModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainMarkFenModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_mark_fen', $data['id'], '基准费用分包费');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }






    public function list_main_jian_chui(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['chui.deleted_user','=', 0];
        $where[] = ['chui.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['chui.name|chui.explain','like', '%'.$param['keyword'].'%'];
        }


        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['chui.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['chui.explain','like', '%'.$param['explain'].'%'];
        }


        $data['data'] = MainJianChuiModel::alias('chui')
            ->field('chui.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_jian_chui', 'chui'))
            ->order('chui.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_jian_chui');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_jian_chui(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainJianChuiModel::insertGetId($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_jian_chui', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_jian_chui', $id, '垂直运输费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'));
        }
    }
    public function edit_main_jian_chui(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            unset($param['token']);

            Db::startTrans();
            try {
                MainJianChuiModel::update($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_jian_chui', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_jian_chui', $param['id'], '垂直运输费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainJianChuiModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function qing_main_jian_chui(Request $request){
        if($request->isPost()){
            $param = $request->post();

            $list = array_filter($param['list']);
            unset($param['list']);

            $paramZhu['updated_user'] = $this->userinfo['id'];
            $paramZhu['updated_at'] = date('Y-m-d H:i:s');

            Db::startTrans();
            try {
                MainJianChuiModel::where(['id'=>$param['id']])->update($paramZhu);

                MainJianChuiListModel::where(['jianid'=>$param['id']])->delete();
                (new MainService())->add_main_jian_chui_list($list, $param['id']);

                (new OptService())->add_flow_log('编辑清单', 'main_jian_chui', $param['id']);
                (new OptService())->add_log_list('编辑清单', 'main_jian_chui', $param['id'], '垂直运输费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            $data['editshi'] = (new MainService())->get_editshi();
            return outputJson(2000,lang('code_2000'),$data);
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainJianChuiModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $list = (new MainService())->get_main_jian_chui_list($data['data']['id']);
            $data['list'] = $list;
            $data['editshi'] = (new MainService())->get_editshi($data['data']['updated_at'],$data['data']['updated_user']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_jian_chui(Request $request){
        $param = $request->post();
        $data = MainJianChuiModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainJianChuiModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_jian_chui', $data['id'], '垂直运输费');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }

    public function list_main_jian_cuo(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['cuo.deleted_user','=', 0];
        $where[] = ['cuo.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['cuo.name|cuo.explain','like', '%'.$param['keyword'].'%'];
        }


        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['cuo.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['cuo.explain','like', '%'.$param['explain'].'%'];
        }


        $data['data'] = MainJianCuoModel::alias('cuo')
            ->field('cuo.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_jian_cuo', 'cuo'))
            ->order('cuo.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_jian_cuo');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_jian_cuo(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainJianCuoModel::insertGetId($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_jian_cuo', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_jian_cuo', $id, '措施费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'));
        }
    }
    public function edit_main_jian_cuo(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            unset($param['token']);

            Db::startTrans();
            try {
                MainJianCuoModel::update($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_jian_cuo', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_jian_cuo', $param['id'], '措施费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainJianCuoModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function qing_main_jian_cuo(Request $request){
        if($request->isPost()){
            $param = $request->post();

            $list = array_filter($param['list']);
            unset($param['list']);

            $paramZhu['updated_user'] = $this->userinfo['id'];
            $paramZhu['updated_at'] = date('Y-m-d H:i:s');

            Db::startTrans();
            try {
                MainJianCuoModel::where(['id'=>$param['id']])->update($paramZhu);

                MainJianCuoListModel::where(['cuoid'=>$param['id']])->delete();

                (new MainService())->add_main_jian_cuo_list($list, $param['id']);

                (new OptService())->add_flow_log('编辑清单', 'main_jian_cuo', $param['id']);
                (new OptService())->add_log_list('编辑清单', 'main_jian_cuo', $param['id'], '措施费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,$e->getMessage());
                return outputJson(4000,lang('code_4000'));
            }
            $data['editshi'] = (new MainService())->get_editshi();
            return outputJson(2000,lang('code_2000'),$data);
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainJianCuoModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $list = (new MainService())->get_main_jian_cuo_list($data['data']['id']);
            $data['list'] = $list;

            $data['editshi'] = (new MainService())->get_editshi($data['data']['updated_at'],$data['data']['updated_user']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_jian_cuo(Request $request){
        $param = $request->post();
        $data = MainJianCuoModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainJianCuoModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_jian_cuo', $data['id'], '措施费');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }

    public function list_main_jian_gong(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['gong.deleted_user','=', 0];
        $where[] = ['gong.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['gong.name|gong.explain','like', '%'.$param['keyword'].'%'];
        }


        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['gong.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['gong.explain','like', '%'.$param['explain'].'%'];
        }


        $data['data'] = MainJianGongModel::alias('gong')
            ->field('gong.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_jian_gong', 'gong'))
            ->order('gong.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_jian_gong');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_jian_gong(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainJianGongModel::insertGetId($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_jian_gong', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_jian_gong', $id, '管理人员工资');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'));
        }
    }
    public function edit_main_jian_gong(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            unset($param['token']);

            Db::startTrans();
            try {
                MainJianGongModel::update($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_jian_gong', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_jian_gong', $param['id'], '管理人员工资');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainJianGongModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function qing_main_jian_gong(Request $request){
        if($request->isPost()){
            $param = $request->post();

            $list = array_filter($param['list']);
            unset($param['list']);

            $paramZhu['updated_user'] = $this->userinfo['id'];
            $paramZhu['updated_at'] = date('Y-m-d H:i:s');

            Db::startTrans();
            try {
                MainJianGongModel::where(['id'=>$param['id']])->update($paramZhu);

                MainJianGongListModel::where(['gongid'=>$param['id']])->delete();

                (new MainService())->add_main_jian_gong_list($list, $param['id']);

                (new OptService())->add_flow_log('编辑清单', 'main_jian_gong', $param['id']);
                (new OptService())->add_log_list('编辑清单', 'main_jian_gong', $param['id'], '管理人员工资');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,$e->getMessage());
                return outputJson(4000,lang('code_4000'));
            }
            $data['editshi'] = (new MainService())->get_editshi();
            return outputJson(2000,lang('code_2000'),$data);
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainJianGongModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $list = (new MainService())->get_main_jian_gong_list($data['data']['id']);
            $data['list'] = $list;

            $data['editshi'] = (new MainService())->get_editshi($data['data']['updated_at'],$data['data']['updated_user']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_jian_gong(Request $request){
        $param = $request->post();
        $data = MainJianGongModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainJianGongModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_jian_gong', $data['id'], '管理人员工资');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }

    public function list_main_jian_guan(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['guan.deleted_user','=', 0];
        $where[] = ['guan.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['guan.name|guan.explain','like', '%'.$param['keyword'].'%'];
        }


        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['guan.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['explain']) && !empty($param['explain'])){
            $where[] = ['guan.explain','like', '%'.$param['explain'].'%'];
        }


        $data['data'] = MainJianGuanModel::alias('guan')
            ->field('guan.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('main_jian_guan', 'guan'))
            ->order('guan.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('main_jian_guan');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_main_jian_guan(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            unset($param['token']);


            Db::startTrans();
            try {
                $id = MainJianGuanModel::insertGetId($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'main_jian_guan', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'main_jian_guan', $id, '管理费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'));
        }
    }
    public function edit_main_jian_guan(Request $request){
        if($request->isPost()){
            $param = $request->post();
            if(empty($param['name'])){
                return outputJson(4000, '请输入名称');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            unset($param['token']);

            Db::startTrans();
            try {
                MainJianGuanModel::update($param);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'main_jian_guan', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'main_jian_guan', $param['id'], '管理费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainJianGuanModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function qing_main_jian_guan(Request $request){
        if($request->isPost()){
            $param = $request->post();

            $list = array_filter($param['list']);
            unset($param['list']);

            $paramZhu['updated_user'] = $this->userinfo['id'];
            $paramZhu['updated_at'] = date('Y-m-d H:i:s');

            Db::startTrans();
            try {
                MainJianGuanModel::where(['id'=>$param['id']])->update($paramZhu);

                MainJianGuanListModel::where(['guanid'=>$param['id']])->delete();

                (new MainService())->add_main_jian_guan_list($list, $param['id']);

                (new OptService())->add_flow_log('编辑清单', 'main_jian_guan', $param['id']);
                (new OptService())->add_log_list('编辑清单', 'main_jian_guan', $param['id'], '管理费');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,$e->getMessage());
                return outputJson(4000,lang('code_4000'));
            }
            $data['editshi'] = (new MainService())->get_editshi();
            return outputJson(2000,lang('code_2000'),$data);
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = MainJianGuanModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $list = (new MainService())->get_main_jian_guan_list($data['data']['id']);
            $data['list'] = $list;

            $data['editshi'] = (new MainService())->get_editshi($data['data']['updated_at'],$data['data']['updated_user']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_main_jian_guan(Request $request){
        $param = $request->post();
        $data = MainJianGuanModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            MainJianGuanModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);

            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'main_jian_guan', $data['id'], '管理费');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }











}
